package com.cskaoyan._05servlet_configcontext;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author Macro_Ray
 * @since 2024/5/3 下午9:08
 */
@WebServlet("/ss6")
public class ServletResponse1 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 设置响应状态码
        response.setStatus(200);

        String info = "<h1>你好</h1>";

        // 设置响应头
        response.setContentType("text/html;charset=UTF-8");
        response.setContentLength(info.getBytes().length);

        // 设置响应体
        PrintWriter writer = response.getWriter();
        writer.write(info);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
